package com.spring.boot.sample.test2.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.spring.boot.sample.test2.bean.TestPojo;
import com.spring.boot.sample.test2.dao.TestPojoDao;

@Service
public class TestPojoService {

	@Autowired
	private TestPojoDao testPojoDao;
	@Autowired
	private RedisTemplate<String,String> redisTemplate;
	
	public List<TestPojo> queryAll(){
		return testPojoDao.queryAll();
	}
	@Cacheable(value="getUser:id")
	public TestPojo  getBykey(int id){
		System.out.println("getBykey 第一次从数据库获取=====："+id);
		return testPojoDao.getByKey(id);
	}
	@CacheEvict(value="getUser:id")
	public void deleteFromCache(int id){
		System.out.println("从缓存中删除===="+id);
	}
}
